#include "editor.h"

Editor::Editor()
{
}
void Editor::init(Engine *engine)
{
    this->_engine = engine;
    this->_scene = this->_engine->openScene("EDITOR");
    this->_initUI();
}
void Editor::_initUI()
{
    this->_initBg();
    this->_initMenuUI();
    this->_initHierarchyUI();
    this->_initAssetUI();
    this->_initSceneUI();
    this->_initToolUI();
    this->_initPropertyUI();
    Event::getInstance().on([this]()
                            { this->_updateWindowSize(0, 0); });
}
void Editor::_initBg()
{
    this->_ndBg = new Node();
    this->_ndBg->name = "Editor-Bg";
    this->_scene->addChild(this->_ndBg);
    this->_ndBg->addSprite();
    this->_ndBg->setSpriteColor(0.0f, 0.0f, 0.0f, 1.0f);
    this->_updateUISize();
}
void Editor::_initMenuUI()
{
    this->_layoutMenu = new LayoutMenu(this->_scene);
}
void Editor::_initHierarchyUI()
{
    this->_layoutHierarchy = new LayoutHierarchy(this->_scene);
}
void Editor::_initAssetUI()
{
    this->_layoutAsset = new LayoutAsset(this->_scene);
}
void Editor::_initSceneUI()
{
    this->_layoutScene = new LayoutScene(this->_scene);
}
void Editor::_initToolUI()
{
    this->_layoutTool = new LayoutTool(this->_scene);
}
void Editor::_initPropertyUI()
{
    this->_layoutProperty = new LayoutProperty(this->_scene);
}
void Editor::_updateUISize()
{
    LayoutConfig::getInstance()->setWindowSize(View::viewWidth, View::viewHeight);
    float mainWidth = LayoutConfig::getInstance()->getMainLayoutWidth();
    float mainHeight = LayoutConfig::getInstance()->getMainLayoutHeight();
    this->_ndBg->setSpriteSize(mainWidth, mainHeight);
}

void Editor::_updateWindowSize(float width, float height)
{
    this->_updateUISize();
    // 更新其他布局
    this->_layoutMenu->updateUISize();
    this->_layoutHierarchy->updateUISize();
    this->_layoutAsset->updateUISize();
    this->_layoutScene->updateUISize();
    this->_layoutTool->updateUISize();
    this->_layoutProperty->updateUISize();
}

Editor::~Editor()
{
}
